
/*
pub fn offset(N: i32, inc: i32) -> i32 {
    if inc > 0 {
        0
    } else {
        (N - 1) * -inc
    }
}
 */

 pub fn offset(N: usize, inc: i32) -> IndexOffset {
    IndexOffset::new(N, inc)
}

pub enum IndexOffsetDirection {
    递减,
    平,
    递增,
}

pub struct IndexOffset {
    pub direction: IndexOffsetDirection,
    pub offset: usize,
    pub indices: Vec<usize>,
    pub len_mustbe: usize,
}
impl IndexOffset {
    pub fn new(N: usize, inc: i32) -> Self {
        if N < 1 {
            panic!("IndexOffset::new N=({N}) < 1");
        }
        if inc > 0 {
            let direction = IndexOffsetDirection::递增;
            let offset = inc as usize;
            let len_mustbe = (N - 1) * offset + 1;
            let mut indices = vec![];
            for i in 0..N {
                indices.push(i * offset);
            }
            Self { direction, offset, indices, len_mustbe }
        } else if inc == 0 {
            let direction = IndexOffsetDirection::平;
            let offset = 0;
            let len_mustbe = N;
            let mut indices = vec![];
            for _ in (0..N).rev() {
                indices.push(0);
            }
            Self { direction, offset, indices, len_mustbe }
        } else {
            let direction = IndexOffsetDirection::递减;
            let offset = -inc as usize;
            let len_mustbe = (N - 1) * offset + 1;
            let mut indices = vec![];
            for i in (0..N).rev() {
                indices.push(i * offset);
            }
            Self { direction, offset, indices, len_mustbe }
        }
        
    }
}